﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/Content/js/common.js"></script>
<script>
    $(function () {
        $("#seProvence").change(function () {
            var Parent = $(this).val();
            if ($("#seCity").find("option").length > 0) {
                $("#seCity").empty();
            }
            if ($("#seQu").find("option").length > 0) {
                $("#seQu").empty();
            }
            GetCity(Parent);
        });
        $("#seCity").change(function () {
            var Parent = $(this).val();
            if ($("#seQu").find("option").length > 0) {
                $("#seQu").empty();
            }
            GetQu(Parent);
        });
        $.ajax({
            url: "/ItemsType/GetChildListByParentID",
            data: { keyValue: "00000000-0000-0000-0000-000000000000" },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#seProvence").append("<option>选择省份</option>");
                $.each(data, function (i) {
                    $("#seProvence").append($("<option></option>").val(data[i].id).html(data[i].text));
                });
            }
        });
        gridList();
    })

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/Shop/GetGridJson",
            height: $(window).height() - 128,
            colModel: [
                { label: '主键', name: 'ID', hidden: true },
                { label: '店面名称', name: 'ShopName', width: 100, align: 'left' },
                { label: '店面地址', name: 'Address', width: 150, align: 'left' },
                {
                    label: '经纬度', name: 'JingWei', width: 150, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return rowObject.Lng + "," + rowObject.Lat;
                    }
                },
                {
                    label: '开业时间', name: 'SetUpTime', width: 66, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return (new Date(rowObject.SetUpTime).format("yyyy-MM-dd"));
                    }
                },
                {
                    label: '营业时间', name: 'SetUpTime', width: 80, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return (new Date(rowObject.OpenStartTime)).format("hh:mm") + "~" + (new Date(rowObject.OpenEndTime)).format("hh:mm");
                    }
                },
                  { label: '添加者', name: 'AddPerson', width: 80, align: 'left' },
                 {
                     label: '添加时间', name: 'AddTime', width: 120, align: 'left',
                     formatter: "date", formatoptions: { srcformat: 'Y-m-d h:m:s', newformat: 'Y-m-d h:m:s' }
                 },
                 { label: '修改者', name: 'ModifyPerson', width: 80, align: 'left' },
                 {
                     label: '修改时间', name: 'ModifyDate', width: 120, align: 'left',
                     formatter: "date", formatoptions: { srcformat: 'Y-m-d h:m:s', newformat: 'Y-m-d h:m:s' }
                 },
                     {
                         label: '是否显示', name: 'IsShow', width: 60, align: 'center',
                         formatter: function (cellvalue, options, rowObject) {
                             if (cellvalue == 1) {
                                 return '显示';
                             } else {
                                 return '不显示';
                             }
                         }
                     },
                     {
                         label: '是否营业', name: 'IsOpen', width: 60, align: 'center',
                         formatter: function (cellvalue, options, rowObject) {
                             if (cellvalue == 1) {
                                 return '营业';
                             } else {
                                 return '不营业';
                             }
                         }
                     }
            ],
            pager: "#gridPager",
            sortname: 'ID asc,UpdateTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: {
                    keyword: $("#txt_keyword").val(),
                    pri: $("#seProvence").val() == "选择省份" ? "" : $("#seProvence").val(),
                    City: $("#seCity").val() == "选择城市" ? "" : $("#seCity").val(),
                    Qu: $("#seQu").val() == "选择地区" ? "" : $("#seQu").val()
                },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增店面",
            url: "/Shop/Form",
            width: "700px",
            height: "510px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().ID;
        $.modalOpen({
            id: "Form",
            title: "修改店面",
            url: "/Shop/Form?keyValue=" + keyValue,
            width: "800px",
            height: "510px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        $.deleteForm({
            url: "/Shop/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().ID },
            prompt: "注：您确定要删除该项数据吗？",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_Open() {
        $.deleteForm({
            url: "/Shop/Open",
            param: { keyValue: $("#gridList").jqGridRowValue().ID },
            prompt: "注：您确定要开始营业吗？",
            loading: "正在执行操作...",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_Close() {
        $.deleteForm({
            url: "/Shop/Close",
            param: { keyValue: $("#gridList").jqGridRowValue().ID },
            prompt: "注：您确定要关闭营业吗？",
            loading: "正在执行操作...",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_Show() {
        $.deleteForm({
            url: "/Shop/Show",
            param: { keyValue: $("#gridList").jqGridRowValue().ID },
            prompt: "注：您确定要在手机端显示该店面信息吗？提示：开启之后，手机端店面列表中将显示该店面信息",
            loading: "正在执行操作...",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_NotShow() {
        $.deleteForm({
            url: "/Shop/NotShow",
            param: { keyValue: $("#gridList").jqGridRowValue().ID },
            prompt: "注：您确定要在隐藏该店面信息吗？提示：开启之后，手机端店面列表中将隐藏该店面信息",
            loading: "正在执行操作...",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().ID;
        $.modalOpen({
            id: "Details",
            title: "查看店面",
            url: "/Shop/Details?keyValue=" + keyValue,
            width: "700px",
            height: "550px",
            btn: null,
        });
    }
    function GetCity(tem) {
        $.ajax({
            url: "/ItemsType/GetChildListByParentID",
            data: { keyValue: tem },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#seCity").append("<option>选择城市</option>");
                $.each(data, function (i) {
                    $("#seCity").append($("<option></option>").val(data[i].id).html(data[i].text));
                });
            }
        });
    }
    function GetQu(tem) {
        $.ajax({
            url: "/ItemsType/GetChildListByParentID",
            data: { keyValue: tem },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#seQu").append("<option>选择地区</option>");
                $.each(data, function (i) {
                    $("#seQu").append($("<option></option>").val(data[i].id).html(data[i].text));
                });
            }
        });
    }
</script>

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新增店面</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改店面</a></li>
                <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除店面</a></li>
                <li><a id="NF-Details" authorize="yes" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看</a></li>
                <li class="split"></li>
                <li><a id="NF-disabled" authorize="yes" onclick="btn_Open()"><i class="fa fa-stop-circle"></i>营业</a></li>
                <li><a id="NF-enabled" authorize="yes" onclick="btn_Close()"><i class="fa fa-play-circle"></i>停业</a></li>
                <li class="split"></li>
                <li><a id="NF-disabled" authorize="yes" onclick="btn_Show()"><i class="fa fa-stop-circle"></i>手机端显示</a></li>
                <li><a id="NF-enabled" authorize="yes" onclick="btn_NotShow()"><i class="fa fa-play-circle"></i>手机端不显示</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="店面名称" style="width: 200px;" maxlength="25">
                        <select id="seProvence" name="seProvence" class="form-control" style="width: 120px;  margin-left: 10px;"  ></select>
                        <select id="seCity" name="seCity" class="form-control" style="width: 120px; margin-left:10px;"  ></select>
                        <select id="seQu" name="seQu" class="form-control" style="width: 120px;   margin-left: 10px; "  ></select>
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
